<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    * {
      margin: 0;
      padding: 0;
    }

    div {
      width: 100px;
      height: 100px;
      background-color: #ccc;
      position: relative;
      left: 0;
    }
  </style>
</head>

<body>
  <div></div>
  <script>
    function interval(delay = 1000, callback) {
      return new Promise((resolve) => {
        let id = setInterval(() => {
          callback(id, resolve)
        }, delay);
      })
    }
    interval(10, function (id, resolve) {
      var div = document.querySelector('div')
      let left = parseInt(div.offsetLeft)
      div.style.left = left + 1 + 'px'
      if (left >= 300) {
        clearInterval(id)
        resolve(div)

      }
    })
      .then((div) => {
        return interval(50,(id, resolve) => {
          let left = parseInt(div.offsetLeft)
          let width = div.offsetWidth
          div.style.width = width - 3 + 'px'
          div.style.left = left + 3 + 'px'
          if (width <= 10) {
            clearInterval(id)
            resolve(div)
          }
        })
      }).then((div)=>{
        div.style.backgroundColor = 'red'
        
      })
  </script>
</body>

</html>